﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase.Tools;
namespace WPFExcelReport
{

    public class DSTPLANData : BaseFunction
    {
        
        public DSTPLANData()
            : base()
        {

        }
        public DSTPLANData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }

        public DataSet GetVKPOS(DataRow dwABPOS)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "VKPOS";
            string ORDERNO = dwABPOS["ORDERNO"].ToString().Trim();
            string SHIPFROMDATE = dwABPOS["SHIPFROMDATE"].ToString().Trim();
            string SHIPENDDATE = dwABPOS["SHIPENDDATE"].ToString().Trim();
            string ORDERFROMDATE = dwABPOS["ORDERFROMDATE"].ToString().Trim();
            string ORDERENDDATE = dwABPOS["ORDERENDDATE"].ToString().Trim();

            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "select * from dstplan a where a.status <> 'J' "
                    + " AND (A.ORDERNO = '" + ORDERNO + "' OR  '" + ORDERNO + "' = 'AAA' ) "
                    + " AND A.REQDATE >= '" + SHIPFROMDATE + "' AND A.REQDATE <= '" + SHIPENDDATE + "' "
                    + " AND A.STARTDATE >= '" + ORDERFROMDATE + "' AND A.STARTDATE <= '" + ORDERENDDATE + "' "
                       + " ORDER BY 3,4 ";
                       /*
                    + " union all "
                    + " select * from v_dstplan a where a.status <> 'J' "
                    + " AND (A.ORDERNO = '" + ORDERNO + "' OR  '" + ORDERNO + "' = 'AAA' ) "
                    + " AND A.REQDATE >= '" + SHIPFROMDATE + "' AND A.REQDATE <= '" + SHIPENDDATE + "' "
                    + " AND A.STARTDATE >= '" + ORDERFROMDATE + "' AND A.STARTDATE <= '" + ORDERENDDATE + "' "
                    + " AND STARTDATE = TO_CHAR(SYSDATE,'YYYYMMDD') "
                    + " ORDER BY 3,4 "
                    ;*/
                
                Result = Connect2Proxy(orlReadCommand);
                if (Result.Tables.Count > 0)
                {
                    Result.Tables[0].TableName = TableName;
                    byte[] b;
                    string value;
                    foreach (DataRow dw in Result.Tables[TableName].Rows)
                    {      
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["NAME"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["NAME"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["YARN"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["YARN"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["BEAM"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["BEAM"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["FACTORY"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["FACTORY"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["SUPPLIER"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["SUPPLIER"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["GPFACTORY"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["GPFACTORY"] = value;
                    }
                }                
                Return.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }
        public DataSet BuildDSTPLANData(DataRow dwUI)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                setResult = GetVKPOS(dwUI);
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        
    }
}